#! /usr/bin/python

########################################################
# Part of MILIM NIRDAFOT project.
# Written by H. Magal, 2014
# See details on the project at the site:
#   https://sites.google.com/site/nirdafotdownloads/home
########################################################

import os
import constants

def main():
    oldname = 'nirdafot.zip'
    try:
        rc = os.stat (oldname)
    except:
        print 'Sorry, nirdafot.zip wasn\'t found'
        return
    constants.set_platform_dependent_vars ()
    # this name is used by many other modules, so don't change it!
    newbasename = 'nirdafotEngine.' + constants.__version__
    newname = newbasename + constants.win_splits_extension
    splitsize = (rc.st_size/constants.splitparts) + 1
    inf = open (oldname, 'rb')                          # open file in binary mode
    for i in xrange(constants.splitparts):
        rd = inf.read (splitsize)                       # read X bytes from file
        outf = open (newname + str(i), 'wb')            # open new binary file
        outf.write (rd)                                 # split input file into N files
        outf.close ()

    inf.close ()
    newname = newbasename + '.zip'
    os.rename (oldname, newname)
    print '   >>> Done ! Renamed to ', newname


if __name__ == '__main__':
    main ()